﻿using UnityEngine;
using System.Collections;

[RequireComponent(typeof(CharacterMovement))]
public class PlayerController : MonoBehaviour 
{
    private CharacterMovement _movement;
    private Vector2 _screenCenter = Vector2.zero;
    void Awake()
    {
        _movement = GetComponent<CharacterMovement>();
        _screenCenter = new Vector2(Screen.width / 2, Screen.height / 2);
    }

    void Update()
    {
        if(Input.touchCount > 0)
        {
            // Assume player is always centered
            _movement.Move((Input.touches[0].position.normalized - _screenCenter).normalized);
        }
        else if(Input.GetMouseButton(0))
        {
            _movement.Move((Input.mousePosition.ToVec2() - _screenCenter).normalized);
        }
    }
}
